/*
 * Copyright (c) 2022.  Asiacom Technology Inc. All rights reserved
 */

package com.swanclouds.model.common;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swanclouds.model.ModelEntity;

import java.util.List;

/**
 * @author 张立强
 * @version jdk1.8.0
 */
@JsonRootName("error")
public class ErrorResponse implements ModelEntity {

	private String code;

	private String message;

	@JsonProperty("@Message.ExtendedInfo")
	private List<ErrorExtendedInfo> extendedInfo;

	public String getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}

	public List<ErrorExtendedInfo> getExtendedInfo() {
		return extendedInfo;
	}

	@JsonRootName("@Message.ExtendedInfo")
	public static class ErrorExtendedInfo implements ModelEntity {

		@JsonProperty("@odata.type")
		private String type;

		@JsonProperty("Message")
		private String message;

		@JsonProperty("MessageId")
		private String messageId;

		@JsonProperty("Resolution")
		private String resolution;

		@JsonProperty("Severity")
		private String severity;

		@JsonProperty("MessageArgs")
		private List<String> messageArgs;

		public String getType() {
			return type;
		}

		public String getMessage() {
			return message;
		}

		public String getMessageId() {
			return messageId;
		}

		public String getResolution() {
			return resolution;
		}

		public String getSeverity() {
			return severity;
		}

		public List<String> getMessageArgs() {
			return messageArgs;
		}

		@Override
		public String toString() {
			ObjectMapper objectMapper = new ObjectMapper();
			try {
				return objectMapper.writeValueAsString(this);
			} catch (JsonProcessingException e) {
			}
			return "ErrorExtendedInfo {" +
					"type='" + type + '\'' +
					", message='" + message + '\'' +
					", messageId='" + messageId + '\'' +
					", resolution='" + resolution + '\'' +
					", severity='" + severity + '\'' +
					", messageArgs=" + messageArgs +
					'}';
		}
	}

	@Override
	public String toString() {
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			return objectMapper.writeValueAsString(this);
		} catch (JsonProcessingException e) {
		}
		return "ErrorResponse {" +
				"code='" + code + '\'' +
				", message='" + message + '\'' +
				", extendedInfo=" + extendedInfo +
				'}';
	}
}
